#include <iostream>
#include <climits>
#include <queue>
#include <algorithm>

using namespace std;

const int N = 100010;
struct Range
{
    int l, r;
    bool operator<(const Range &W) const
    {
        return l < W.l;
    }
} range[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d %d", &range[i].l, &range[i].r);
    }
    sort(range, range + n);
    priority_queue<int, vector<int>, greater<int>> h;
    for (int i = 0; i < n; ++i)
    {
        auto r = range[i];
        if (h.empty() || h.top() >= r.l)
        {
            h.push(r.r);
        }
        else // r.l > h.top()
        {
            h.pop();
            h.push(r.r);
        }
    }
    printf("%d", h.size());
    return 0;
}